package com.example.Dietproject.themenu.controller;

import com.example.Dietproject.themenu.entity.DietThemenu;
import com.example.Dietproject.themenu.service.ThemenuServlce;
import com.example.Dietproject.vegetables.entity.Diet_vegetables;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/Themenu")
public class dietThemenuController {

    @Autowired
    private ThemenuServlce themenuServlce;

    @RequestMapping("/getAll")
    public String getAll(Model m){
        try {
            List<DietThemenu> list=themenuServlce.getAll();
            m.addAttribute("themen",list);
        }catch (Exception e){
            e.getMessage();
        }
        return "inventory";
    }


    @RequestMapping("/delete")
    public  String deleteById(int tid,Model m){
        try {
            int count = themenuServlce.deleteDietThemenuById(tid);
        }catch (Exception e){
            e.getMessage();
        }
        return "inventory";   //删除跳查询页面
    }
    //根据id查询出来
    @RequestMapping("/findByTid")
    public String vegetabupdate(Integer tid,Model model){
        try {
            DietThemenu list = themenuServlce.findDietThemenuByIds(tid);
            model.addAttribute("dietThem",list);
        }catch (Exception e){
            e.getMessage();
        }
        return "themenuupdate";
    }
}
